#!/usr/bin/python

source_dir="/me/MiChangSheng_Mod/Taiwu\\!"
source_dir="" # 如果你没有源码目录，应该取消这一行的注释 如果你是windows，你需要参考旧版Mod自己改引用dll的位置

if __name__ == '__main__':
  import os
  import multiprocessing
  os.chdir(os.path.dirname(__file__)) if os.path.dirname(__file__)!='' else None
  list=[]
  for i in os.listdir():
    try:
      os.chdir(i)
      print(os.getcwd())
      for j in os.listdir():
        if j[-3:]==".cs":
          if not os.path.exists(j[:-3]+".dll") or os.path.getmtime(j)>os.path.getmtime(j[:-3]+".dll"):
            print("    compile "+j+" since it is newer than "+j[:-3]+".dll")
            with open(j,encoding='utf8') as f:
              i=multiprocessing.Process(target=os.system,args=('/'.join(f.readline().split('/')[2:]).replace('$DOTNET_CSC_DLL',r'"C:\Program Files\dotnet\sdk\6.0.400\Roslyn\bincore\csc.dll"').replace('../../../../compatdata/838350/pfx/drive_c/','C:/'),))
              i.start()
              list.append(i)
#          else:
#            print("        do not compile "+j+" since it is newest version")
      os.chdir('..')
    except FileNotFoundError as e:
      continue
    except NotADirectoryError:
      continue
  for i in list:
    i.join()

if len(source_dir)>0:
  os.system("cp -r . "+source_dir)
  os.system("find "+source_dir+" -iname '*.dll' -delete")
  os.system("7z a -r ../Mod.7z .")
  os.chdir(source_dir.replace("\\",''))
  os.system("git add *")
  # commit 就手工来吧
